package com.xyht.sca_s.student_manage_system.modules.user.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.annotation.RepeatRequestCheck;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.user.entity.SmsApplicationClick;
import com.xyht.sca_s.student_manage_system.modules.user.entity.SmsApplicationCollection;
import com.xyht.sca_s.student_manage_system.modules.user.entity.SmsApplicationPoint;
import com.xyht.sca_s.student_manage_system.modules.user.entity.req.SmsApplicationUpdateReq;
import com.xyht.sca_s.student_manage_system.modules.user.service.SmsApplicationService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 界面应用 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2022-12-24
 */
@RestController
@RequestMapping("/application")
@SecretBody
public class SmsApplicationController {
    @Autowired
    private SmsApplicationService smsApplicationService;
    @Autowired
    private JwtTokenUtil jwtTokenUtil;

    @ApiModelProperty(value = "后台获取应用列表")
    @GetMapping("/list")
    public ResponseResult getAppList (@RequestParam("app_client")Integer app_client,
                                      @RequestParam(value = "search_str",required = false)String search_str,
                                      @RequestParam(value = "type_id",required = false)String type_id
    ) {
        return smsApplicationService.getAppList(app_client,search_str,type_id);
    }

    @ApiModelProperty(value = "应用展示获取应用列表")
    @GetMapping("/get")
    public ResponseResult userUseGetAppList (@RequestParam("app_client")Integer app_client,
                                             @RequestParam(value = "is_collection" ,required = false)Integer is_collection,
                                             @RequestParam(value = "search_str",required = false)String search_str,
                                             HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsApplicationService.userUseGetAppList(user_id,app_client,is_collection,search_str);
    }

    @ApiModelProperty(value = "修改应用信息")
    @PostMapping("/update")
    public ResponseResult updateApp (@RequestBody SmsApplicationUpdateReq smsApplicationReq) {
        return smsApplicationService.updateApp(smsApplicationReq);
    }

    @ApiModelProperty(value = "添加应用")
    @PostMapping("/add")
    public ResponseResult addApp (@RequestBody SmsApplicationUpdateReq smsApplicationReq) {
        return smsApplicationService.addApp(smsApplicationReq);
    }

    @ApiModelProperty(value = "添加收藏")
    @PostMapping("/collection")
    @RepeatRequestCheck(name = "appCollection")
    public ResponseResult appCollection (@RequestBody SmsApplicationCollection smsApplicationCollection,
                                         HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsApplicationService.appCollection(user_id,smsApplicationCollection);
    }

    @ApiModelProperty(value = "取消收藏")
    @PostMapping("/cancelCollection")
    @RepeatRequestCheck(name = "appCollectionCancel")
    public ResponseResult appCollectionCancel (@RequestBody SmsApplicationCollection smsApplicationCollection,
                                         HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsApplicationService.appCollectionCancel(user_id,smsApplicationCollection);
    }

    @ApiModelProperty(value = "应用点击访问")
    @PostMapping("/click")
    @RepeatRequestCheck(name = "appClick")
    public ResponseResult appClick (@RequestBody SmsApplicationClick smsApplicationClick,
                                         HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsApplicationService.appClick(user_id,smsApplicationClick);
    }

    @ApiModelProperty(value = "用户评分")
    @PostMapping("/point")
    @RepeatRequestCheck(name = "appPoint")
    public ResponseResult appPoint (@RequestBody SmsApplicationPoint smsApplicationPoint,
                                         HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsApplicationService.appPoint(user_id,smsApplicationPoint);
    }


}

